<template>
	<div class="count">
		<h2>我是Count组件</h2>
		<h3>当前求和为：{{sum}}，下方Person组件总人数为：{{persons.length}}</h3>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="JIA(n)">+</button>
		<button @click="JIAN(n)">-</button>
		<button @click="jiaOdd(n)">当前的和为奇数+</button>
		<button @click="jiaServer">联系服务器+</button>
	</div>
</template>

<script>
	import {mapState,mapActions,mapMutations} from 'vuex'

	export default {
		name:'Count',
		data() {
			return {
				n:1
			}
		},
		computed:{
			...mapState(['sum','persons']) //映射state
		},
		methods: {
			...mapMutations(['JIA','JIAN']), //映射actions
			...mapActions(['jiaOdd','jiaServer']),//映射mutations
		},
	}
</script>

<style scoped>
	.count{
		background-color: skyblue;
		padding: 30px;
	}
	*{
		margin-right: 10px;
	}
</style>